package com.summer.framework.common.entity.response;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @auther: 杨杰
 * @date: 2019/1/14 09:33
 * @description:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ObjectResponse<T> extends BaseResponse {
    private T data;

    public ObjectResponse(Integer status, String message, T data) {
        super(status, message);
        this.data = data;
    }

    public ObjectResponse(Integer status, T data) {
        this(status, "", data);
    }


    public static final class ObjectResponseBuilder<T> {
        private T data;
        private Integer status = HttpStatus.OK.value();
        private String message;

        private ObjectResponseBuilder() {
        }

        public static ObjectResponseBuilder anObjectResponse() {
            return new ObjectResponseBuilder();
        }

        public ObjectResponseBuilder withData(T data) {
            this.data = data;
            return this;
        }

        public ObjectResponseBuilder withStatus(Integer status) {
            this.status = status;
            return this;
        }

        public ObjectResponseBuilder withMessage(String message) {
            this.message = message;
            return this;
        }

        public ObjectResponse build() {
            ObjectResponse objectResponse = new ObjectResponse();
            objectResponse.setData(data);
            objectResponse.setStatus(status);
            objectResponse.setMessage(message);
            return objectResponse;
        }
    }
}
